package com.zwy.leetcode;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Day13Test {
    /**
     * 1131. 绝对值表达式的最大值
     * @param arr1
     * @param arr2
     * @return
     */
    public int maxAbsValExpr(int[] arr1, int[] arr2) {
        int amin = Integer.MAX_VALUE, bmin = Integer.MAX_VALUE, cmin = Integer.MAX_VALUE, dmin = Integer.MAX_VALUE;
        int amax = Integer.MIN_VALUE, bmax = Integer.MIN_VALUE, cmax = Integer.MIN_VALUE, dmax = Integer.MIN_VALUE;

        for(int i = 0; i < arr1.length; i++) {
            amin = Math.min(amin, arr1[i]+arr2[i]+i);
            amax = Math.max(amax, arr1[i]+arr2[i]+i);

            bmin = Math.min(bmin, arr1[i]+arr2[i]-i);
            bmax = Math.max(bmax, arr1[i]+arr2[i]-i);

            cmin = Math.min(cmin, arr1[i]-arr2[i]+i);
            cmax = Math.max(cmax, arr1[i]-arr2[i]+i);

            dmin = Math.min(dmin, arr1[i]-arr2[i]-i);
            dmax = Math.max(dmax, arr1[i]-arr2[i]-i);
        }

        return Math.max(Math.max(amax-amin, bmax-bmin), Math.max(cmax-cmin, dmax-dmin));


    }

    String[][]res=null;

    /**
     * 剑指 Offer II 086. 分割回文子字符串
     * @param s
     * @return
     */
    public String[][] partition(String s) {
        String s1="";
        return null;
    }
    int count=0;
    public void backTrack0(String s1,int start){
        if(count==s1.length()){

        }
    }

    /**
     *
     * @param nums
     * @return
     */
    public boolean isStraight(int[] nums) {
        int zeroNum=0;
        int t=14;
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]==t&&nums[i]!=0)return false;
            t=nums[i];
            if(nums[i]==0)zeroNum++;
        }
        if(nums[nums.length-1]-nums[zeroNum]<=4)return true;
        return false;
    }

    /**
     * 709. 转换成小写字母
     * @param s
     * @return
     */
    public String toLowerCase(String s) {
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(s.charAt(i)>=65&&s.charAt(i)<=90)chars[i]+=32;
        }
        return new String(chars);
    }

    /**
     * 447. 回旋镖的数量
     * @param points
     * @return
     */
    public int numberOfBoomerangs(int[][] points) {
        Map<String,Integer>map=new HashMap<>();
        int r=0;
        int res=0;
        for (int i = 0; i < points.length; i++) {
            for (int j = 0; j < points.length; j++) {
                if(i!=j){
                    r=(points[i][0]-points[j][0])*(points[i][0]-points[j][0])+(points[i][1]-points[j][1])*(points[i][1]-points[j][1]);
                    if(!map.containsKey(i+","+r))map.put(i+","+r,1);
                    else map.put(i+","+r,map.get(i+","+r)+1);
                }
            }
        }
        Set<String> set = map.keySet();
        for (String s : set) {
            Integer count = map.get(s);
            if(count>1){
                res+=(count)*(count-1);
            }
        }
        return res;
    }

    /**
     * 464. 我能赢吗
     * @param maxChoosableInteger
     * @param desiredTotal
     * @return
     */
    public boolean canIWin(int maxChoosableInteger, int desiredTotal) {

        return false;
    }

    /**
     * 1140. 石子游戏 II
     * @param piles
     * @return
     */
    public int stoneGameII(int[] piles) {
        return 0;
    }

    /**
     * 877. 石子游戏
     * @param piles
     * @return
     */
//    public boolean stoneGame(int[] piles) {
//
//    }




    public static void main(String[] args) {
        int [][]arr1={{0,0},{1,0},{2,0},{3,0},{4,0}};
        String s = "LOVELY";
        int  []arr2 = {0,-2,-1,-7,-4};
        Day13Test test=new Day13Test();
          test.numberOfBoomerangs(arr1);
//        System.out.println(i);

    }
}
